var express = require('express');
var router = express.Router();
var connection = require('../db/sql.js');
var user = require('../db/UserSql.js');
//全局的验证码
let code = ''

//后端express解决接口跨域
router.all("*",function(req,res,next){
	//设置允许跨域的域名，*代表允许任意域名跨域
	res.header("Access-Control-Allow-Origin","*");
	//允许的header类型
	res.header("Access-Control-Allow-Headers","content-type");
	//跨域允许的请求方式
	res.header("Access-Control-Allow-Methods","*");
	res.hasHeader('Content-Type','application/json;charset=utf-8');
	next();
});

//查询当前用户的地址信息
router.get('/api/setAddress', function(req, res, next) {
	// let token = req.header.token;
	res.send({
		code:1,
		msg:success,
		data:1234
	})
});
//发送手机验证码， 接入手机短信SDK-------------------------------------------------------------
router.post('/api/code', function(req, res, next) {
	
	//前端给后端的数据手机号
	let params = {
		userName : req.body.userName
	};
	//随机生成验证码
	// code = [Math.floor(Math.random()*(999-1000))+1000];
	code = '1234';
	res.send({
		data:{
			success:true,
			msg:"手机验证码发送成功",
			code: code,
		}
	})
	//接入短信SDK
});

//增加一条记录
router.post('/api/addUser', function(req, res, next) {
	
	//前端给后端的数据手机号
	let params = {
		userName : req.body.userName,
		userCode : req.body.code
	}
	if( params.userCode == code ){
		//增加一条数据
		connection.query( user.insertData( params ) , function (error, results, fields) {
			res.send({
				data:{
					success:true,
					msg:"手机号注册成功"
				}
			})
		})
	}
	//接入短信SDK
});
//我的页面相关接口-------------------------------------------------------------------------------------------------
//用户登录
// router.post('/api/login', function(req, res, next) {
router.post('/api/login', function(req, res, next) {
	
	//前端给后端的数据
	let params = {
		userName : req.body.userName,
		userPwd  : req.body.userPwd
	}
	//查询用户名或者手机号存在不存在
	 connection.query( user.queryUserName( params ) , function (error, results, fields) {
		if( results.length > 0 ){
			 connection.query( user.queryUserPwd( params ) , function (err, result) {
				 if(  result.length > 0 ){
					 res.send({
						data:{
							success:true,
							msg:"登录成功",
							data:result[0]
						}
					 })
				 }else{
					res.send({
					data:{
						success:false,
						msg:"密码不正确"
					}
					})
				 }
			 })
		}else{
			res.send({
				data:{
					success:false,
					msg:"用户名或手机号不存在"
				}
			})
		}
	 })
});
// 判断注册手机号验证是否存在
router.post('/api/registered', function(req, res, next) {
	//前端给后端传数据
	let params = {
		//与sql语句保持一致
		userName : req.body.phone
	};
	//查询手机号是否存在
	connection.query( user.queryUserName( params ) , function (error, results, fields) {
		if(results.length > 0){
			res.send({
				data:{
					success:false,
					msg:"手机号已经注册过了，可以前往登录",
					data:{}
				}
			})
		}else{
			res.send({
				data:{
					success:true
				}
			})
		}
	})
});


//首页数据相关接口---------------------------------------------------------------------------------------------------
// 运动户外第一次触底的数据
router.get('/api/index_list/2/data/2', function(req, res, next) {
	res.json({
		"code":0,
		"data":[
			{
				"type":'commodityList',
				"data":[
					{
						id:1,
						imgUrl:"../../static/img/goods1.jpg",
						name:"茶叶222222222222222222，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:2,
						imgUrl:"../../static/img/goods1.jpg",
						name:"普洱茶",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:3,
						imgUrl:"../../static/img/goods1.jpg",
						name:"茶叶222222222222222222，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					}
				]
			},
		],
	})
});
// 运动户外第二次触底的数据
router.get('/api/index_list/2/data/3', function(req, res, next) {
	res.json({
		"code":0,
		"data":[
			{
				"type":'commodityList',
				"data":[
					{
						id:1,
						imgUrl:"../../static/img/goods4.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:2,
						imgUrl:"../../static/img/goods4.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:3,
						imgUrl:"../../static/img/goods4.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:4,
						imgUrl:"../../static/img/goods4.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					}
				]
			},
		],
	})
});

//首页第一次触底的数据请求
router.get('/api/index_list/1/data/2', function(req, res, next) {
  res.send({
		"code":0,
	"data":[
		{
			"type":'commodityList',
			"data":[
				{
					id:1,
					imgUrl:"../../static/img/goods3.jpg",
					name:"茶叶，选取优质地带，不容错过，爆款",
					pprice:"499",
					oprice:"699",
					discount:"5.2"
				},
				{
					id:2,
					imgUrl:"../../static/img/goods1.jpg",
					name:"茶叶，选取优质地带，不容错过，爆款",
					pprice:"499",
					oprice:"699",
					discount:"5.2"
				},
				{
					id:3,
					imgUrl:"../../static/img/goods3.jpg",
					name:"茶叶，选取优质地带，不容错过，爆款",
					pprice:"499",
					oprice:"699",
					discount:"5.2"
				},
				{
					id:4,
					imgUrl:"../../static/img/goods1.jpg",
					name:"茶叶，选取优质地带，不容错过，爆款",
					pprice:"499",
					oprice:"699",
					discount:"5.2"
				}
			]
		},
	]
  })
});
//首页数据请求
router.get('/api/index_list/data', function(req, res, next) {
  res.send({
		"code":0,
		"data":{
			topBar:[
				{id:1,name:'推荐'},
				{id:2,name:'运动户外'},
				{id:3,name:'服饰内衣'},
				{id:4,name:'鞋包推荐'},
				{id:5,name:'美妆护肤'},				
				{id:6,name:'家具家电'},
				{id:7,name:'母婴好物'}
			],
			"data":[
				{
					"type":'swiperList',
					"data":[
						{imgUrl:'../../static/img/swiper1.jpeg'},
						{imgUrl:'../../static/img/swiper2.jpeg'},
						{imgUrl:'../../static/img/swiper3.jpeg'}
					]
				},
				{
					"type":'recommendList',
					"data":[
						{
							bigUrl:'../../static/img/recommend.jpeg',
							data:[
								{imgUrl:'../../static/img/like1.jpeg'},
								{imgUrl:'../../static/img/like2.jpeg'},
								{imgUrl:'../../static/img/like3.jpeg'}
							]
						},
						{
							bigUrl:'../../static/img/recommend.jpeg',
							data:[
								{imgUrl:'../../static/img/like1.jpeg'},
								{imgUrl:'../../static/img/like2.jpeg'},
								{imgUrl:'../../static/img/like3.jpeg'}
							]
						},
					]
				},
				{
					"type":'commodityList',
					"data":[
						{
							id:1,
							imgUrl:"../../static/img/goods3.jpg",
							name:"茶叶，选取优质地带，不容错过，爆款",
							pprice:"499",
							oprice:"699",
							discount:"5.2"
						},
						{
							id:2,
							imgUrl:"../../static/img/goods1.jpg",
							name:"茶叶，选取优质地带，不容错过，爆款",
							pprice:"499",
							oprice:"699",
							discount:"5.2"
						},
						{
							id:3,
							imgUrl:"../../static/img/goods3.jpg",
							name:"茶叶，选取优质地带，不容错过，爆款",
							pprice:"499",
							oprice:"699",
							discount:"5.2"
						},
						{
							id:4,
							imgUrl:"../../static/img/goods1.jpg",
							name:"茶叶，选取优质地带，不容错过，爆款",
							pprice:"499",
							oprice:"699",
							discount:"5.2"
						}
					]
				},
				
			]
		}
  })
});

// 运动户外第一次加载的数据
router.get('/api/index_list/2/data/1', function(req, res, next) {
	res.json({
		"code":0,
		"data":[
			{
				type:"bannerList",
				imgUrl:"../../static/img/dhp.jpeg"
			},
			{
				type:"iconsList",
				data:[
					{imgUrl:"../../static/img/icons1.png",title:"运动户外"},
					{imgUrl:"../../static/img/icons2.png",title:"运动户外"},
					{imgUrl:"../../static/img/icons3.png",title:"运动户外"},
					{imgUrl:"../../static/img/icons4.png",title:"运动户外"},
					{imgUrl:"../../static/img/icons5.png",title:"运动户外"},
					{imgUrl:"../../static/img/icons6.png",title:"运动户外"},
					{imgUrl:"../../static/img/icons7.png",title:"运动户外"},
					{imgUrl:"../../static/img/icons8.png",title:"运动户外"},
				]
			},
			{
				type:"hotList",
				data:[
					{
						id:1,
						imgUrl:"../../static/img/goods3.jpg",
						name:'茶叶222222，选取优质地带，不容错过，爆款',
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:2,
						imgUrl:"../../static/img/goods3.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:3,
						imgUrl:"../../static/img/goods3.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:4,
						imgUrl:"../../static/img/goods3.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					}
				]
			},
			{
				type:'shopList',
				data:[
					{
						bigUrl:'../../static/img/swiper1.jpeg',
						data:[
							{
								id:1,
								imgUrl:"../../static/img/goods3.jpg",
								name:'茶叶，选取优质地带，不容错过，爆款',
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:2,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:3,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:4,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:5,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:6,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:7,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							}
							],
					},
					{
						bigUrl:'../../static/img/swiper3.jpeg',
						data:[
							{
								id:1,
								imgUrl:"../../static/img/goods3.jpg",
								name:'茶叶，选取优质地带，不容错过，爆款',
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:2,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:3,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							}
							],
					}
				],
			},
			{
				"type":'commodityList',
				"data":[
					{
						id:1,
						imgUrl:"../../static/img/goods3.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:2,
						imgUrl:"../../static/img/goods3.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:3,
						imgUrl:"../../static/img/goods3.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:4,
						imgUrl:"../../static/img/goods3.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					}
				]
			},
		]
	})
});
/* 服饰内衣第一次加载数据. */
router.get('/api/index_list/3/data/1', function(req, res, next) {
	res.json({
		"code":0,
		"data":[
			{
				type:"bannerList",
				imgUrl:"../../static/img/dhp.jpeg"
			},
			{
				type:"iconsList",
				data:[
					{imgUrl:"../../static/img/icons1.png",title:"服饰内衣"},
					{imgUrl:"../../static/img/icons2.png",title:"服饰内衣"},
					{imgUrl:"../../static/img/icons3.png",title:"服饰内衣"},
					{imgUrl:"../../static/img/icons4.png",title:"服饰内衣"},
					{imgUrl:"../../static/img/icons5.png",title:"服饰内衣"},
					{imgUrl:"../../static/img/icons1.png",title:"服饰内衣"},
					{imgUrl:"../../static/img/icons2.png",title:"服饰内衣"},
					{imgUrl:"../../static/img/icons3.png",title:"服饰内衣"},
				]
			},
			{
				type:"hotList",
				data:[
					{
						id:1,
						imgUrl:"../../static/img/goods3.jpg",
						name:'茶叶，选取优质地带，不容错过，爆款',
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:2,
						imgUrl:"../../static/img/goods1.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:3,
						imgUrl:"../../static/img/goods3.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:4,
						imgUrl:"../../static/img/goods1.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					}
				]
			},
			{
				type:'shopList',
				data:[
					{
						bigUrl:'../../static/img/swiper3.jpeg',
						data:[
							{
								id:1,
								imgUrl:"../../static/img/goods3.jpg",
								name:'茶叶，选取优质地带，不容错过，爆款',
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:2,
								imgUrl:"../../static/img/goods1.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:3,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:4,
								imgUrl:"../../static/img/goods1.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:5,
								imgUrl:"../../static/img/goods1.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:6,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:7,
								imgUrl:"../../static/img/goods1.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							}
							],
					},
					{
						bigUrl:'../../static/img/swiper3.jpeg',
						data:[
							{
								id:1,
								imgUrl:"../../static/img/goods3.jpg",
								name:'茶叶，选取优质地带，不容错过，爆款',
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:2,
								imgUrl:"../../static/img/goods1.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:3,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:4,
								imgUrl:"../../static/img/goods1.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:5,
								imgUrl:"../../static/img/goods1.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:6,
								imgUrl:"../../static/img/goods3.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							},
							{
								id:7,
								imgUrl:"../../static/img/goods1.jpg",
								name:"茶叶，选取优质地带，不容错过，爆款",
								pprice:"499",
								oprice:"699",
								discount:"5.2"
							}
							],
					}
					],
			},
			{
				"type":'commodityList',
				"data":[
					{
						id:1,
						imgUrl:"../../static/img/goods3.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:2,
						imgUrl:"../../static/img/goods1.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:3,
						imgUrl:"../../static/img/goods3.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					},
					{
						id:4,
						imgUrl:"../../static/img/goods1.jpg",
						name:"茶叶，选取优质地带，不容错过，爆款",
						pprice:"499",
						oprice:"699",
						discount:"5.2"
					}
				]
			},
		]	
	})
});

//分类页面相关接口-----------------------------------------------------------------------------------------------
//搜索页数据的，升序和降序，及查找商品
router.get("/api/goods/search", function(req, res, next) {
	//desc降序，  asc升序
	// 拿到前端传过来的数据
	let [goodsName,orderName] = Object.keys(req.query);
	//name参数的值
	let name = req.query.name;
	//orderName的key的值
	let order = req.query[orderName];
	
	connection.query("select * from goods_search where name like '%"+name+"%' order by "+orderName+" "+order+" ", function(error,results,fields){
		if(error) throw error;
		res.send({
			code:"0",
			data:results
		})
	});
});
// 分类商品列表
router.get('/api/goods/list', function(req, res, next) {
   res.json({
	   code:0,
	   data:[
		   {
			   id:1,
			   name:"家居家纺",
			   data:[
				   {
					   name:"家纺",
					   list:[
						   {
							   id:1,
							   name:"毛巾/浴巾",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:2,
							   name:"枕头",
							   imgUrl:"../../static/img/list1.jpg"
						   },						   
						   {
							   id:3,
							   name:"毛巾/浴巾",
							   imgUrl:"../../static/img/goods3.jpg"
						   },
						   {
							   id:4,
							   name:"枕头",
							   imgUrl:"../../static/img/goods4.jpg"
						   }
					   ]
				   },
				   {
					   name:"生活用品",
					   list:[
						   {
							   id:1,
							   name:"浴室用品",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:2,
							   name:"洗晒",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:3,
							   name:"毛巾/浴巾",
							   imgUrl:"../../static/img/goods3.jpg"
						   },
						   {
							   id:4,
							   name:"枕头",
							   imgUrl:"../../static/img/goods4.jpg"
						   }
					   ]
				   },				  
				   {
					   name:"家纺",
					   list:[
						   {
							   id:1,
							   name:"毛巾/浴巾",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:2,
							   name:"枕头",
							   imgUrl:"../../static/img/list1.jpg"
						   },{
							   id:3,
							   name:"毛巾/浴巾",
							   imgUrl:"../../static/img/goods3.jpg"
						   },
						   {
							   id:4,
							   name:"枕头",
							   imgUrl:"../../static/img/goods4.jpg"
						   }
					   ]
				   },
				   {
					   name:"生活用品",
					   list:[
						   {
							   id:1,
							   name:"浴室用品",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:2,
							   name:"洗晒",
							   imgUrl:"../../static/img/list1.jpg"
						   }
					   ]
				   },				   {
					   name:"家纺",
					   list:[
						   {
							   id:1,
							   name:"毛巾/浴巾",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:2,
							   name:"枕头",
							   imgUrl:"../../static/img/list1.jpg"
						   }
					   ]
				   },
				   {
					   name:"生活用品",
					   list:[
						   {
							   id:1,
							   name:"浴室用品",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:2,
							   name:"洗晒",
							   imgUrl:"../../static/img/list1.jpg"
						   }
					   ]
				   }
			   ]
		   },
		   {
			   id:2,
			   name:"女装",
			   data:[
				   {
					   name:"裙装",
					   list:[
						   {
							   id:1,
							   name:"半身裙",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:2,
							   name:"连衣裙",
							   imgUrl:"../../static/img/list1.jpg"
						   }
					   ]
				   },
				   {
					   name:"上衣",
					   list:[
						   {
							   id:1,
							   name:"T恤",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:2,
							   name:"衬衫",
							   imgUrl:"../../static/img/list1.jpg"
						   }
					   ]
				   }
			   ]
		   },
		   {
			   id:3,
			   name:"男装",
			   data:[
				   {
					   name:"外衣",
					   list:[
						   {
							   id:1,
							   name:"西装",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:2,
							   name:"大衣",
							   imgUrl:"../../static/img/list1.jpg"
						   }
					   ]
				   },
				   {
					   name:"上衣",
					   list:[
						   {
							   id:1,
							   name:"T恤",
							   imgUrl:"../../static/img/list1.jpg"
						   },
						   {
							   id:2,
							   name:"衬衫",
							   imgUrl:"../../static/img/list1.jpg"
						   }
					   ]
				   }
			   ]
		   }
	   ]
   })
});

//根据id获取点击商品的信息
router.get('/api/goods/id', function(req, res, next) {
  let id = req.query.id;
  connection.query("select * from goods_search where id="+id+"", function (error, results, fields) {
    if (error) throw error;
    res.send({
  	  code:"0",
  	  data:results
    })
  });
});

module.exports = router;
